<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Newsletter_model extends Model
{
	private $_host;
	private $_dbname;
	private $_username;
	private $_password;
	private $_port;
	function Newsletter_model()
	{
		parent::Model();
		
		$host = $this->db->hostname;
		$arrHost = explode(':',$host);
		
		$this->_host = trim($arrHost[0]);
		$this->_dbname = $this->db->database;
		$this->_username = $this->db->username;
		$this->_password = $this->db->password;
		$this->_port = $this->db->port;
	}
	
	function get_list_user($cPage, $numItem)
	{
		$start = ($cPage - 1) * $numItem;
		
		$data = array();
		$data['lstUser'] = array();
		$data['iCount'] = 0;
		$data['pCount'] = 0;
		
		mysqli_multi_query($this->db->conn_id, "CALL selfserving_admin_newsletter_list_mail('$start', '$numItem');") or die(show_custom_error(mysqli_error($this->db->conn_id )));
		$result = mysqli_store_result($this->db->conn_id);
		while($row = mysqli_fetch_array($result))
		{
			$data['lstUser'][] = $row;
		}
		mysqli_free_result($result);
		if(mysqli_more_results($this->db->conn_id))
		{
			mysqli_next_result($this->db->conn_id);
		}
		
		mysqli_next_result($this->db->conn_id);
        $result = mysqli_store_result($this->db->conn_id);
        $row = mysqli_fetch_array($result);
        $data['iCount'] = $row[0];
        mysqli_free_result($result);
		if(mysqli_more_results($this->db->conn_id))
		{
			mysqli_next_result($this->db->conn_id);
		}
		
		$data['pCount'] = ($data['iCount'] > $numItem) ? ceil($data['iCount']/$numItem) : 1;
		return $data;
	}
	
 }